*FIRES
use "$dataDir/dataset_fires_harvest_daily_weather", clear

collapse (sum) shf, by(year treatment id_mills)

collapse (mean) shf, by(year treatment)

*Panel A
	twoway (line shf year if treatment==1) (line shf year if treatment ==0), legend(label(1 "Regulated") label(2 "Unregulated") pos(6) cols(2)) ytitle(Annual sugarcane fires) xline(2015) ylabel(0(20)100) xlab(, nogrid) xtitle("")
		graph export "$mainDir/figures/FigA7_panelA_trends_fires.pdf", as(pdf) replace
		
*INPUTS
use "$dataDir/dataset_admin_field", clear


collapse (mean) sug_manual_cut sug_mecanic_cut tech_total_cutters, by(year treatment id_mills)

collapse (mean) sug_manual_cut sug_mecanic_cut tech_total_cutters, by(year treatment)		

*Panel B	
		twoway (line sug_manual_cut year if treatment==1) (line sug_manual_cut year if treatment ==0), legend(label(1 "Regulated") label(2 "Unregulated") pos(6) cols(2)) ytitle(Manual cut (tons)) xline(2015) ylabel(0(10000)60000) xlab(, nogrid) xtitle("")
			graph export "$mainDir/figures/FigA7_panelB_trends_sug_manual_cut.pdf", as(pdf) replace
*Panel C
		twoway (line sug_mecanic_cut year if treatment==1) (line sug_mecanic_cut year if treatment ==0), legend(label(1 "Regulated") label(2 "Unregulated") pos(6) cols(2)) ytitle(Mechanical cut (tons)) xline(2015)	ylabel(0(2000)12000) xlab(, nogrid) xtitle("")
			graph export "$mainDir/figures/FigA7_panelC_trends_sug_mecanic_cut.pdf", as(pdf) replace
*Panel D		
		twoway (line tech_total_cutters year if treatment==1) (line tech_total_cutters year if treatment ==0), legend(label(1 "Regulated") label(2 "Unregulated") pos(6) cols(2)) ytitle(Field workers) xline(2015) ylabel(0(400)2400) xlab(, nogrid) xtitle("")
			graph export "$mainDir/figures/FigA7_panelD_trends_tech_total_cutters.pdf", as(pdf) replace
		
*OUTPUTS
use "$dataDir/dataset_admin_fabrica", clear
		
collapse (mean) sugarcaneprocessedraw  total_sugar_production, by(year treatment id_mills)

collapse (mean) sugarcaneprocessedraw  total_sugar_production, by(year treatment)

*Panel E			
		twoway (line sugarcaneprocessedraw year if treatment==1) (line sugarcaneprocessedraw year if treatment ==0), legend(label(1 "Regulated") label(2 "Unregulated") pos(6) cols(2)) ytitle(Raw processed sugarcane (tons)) xline(2015) ylabel(0(10000)60000) xlab(, nogrid) xtitle("")
			graph export "$mainDir/figures/FigA7_panelE_trends_sugarcaneprocessedraw.pdf", as(pdf) replace
*Panel F		
		twoway (line total_sugar_production year if treatment==1) (line total_sugar_production year if treatment ==0), legend(label(1 "Regulated") label(2 "Unregulated") pos(6) cols(2)) ytitle(Sugar produced (tons)) xline(2015)	ylabel(0(1000)6000) xlab(, nogrid) xtitle("")
			graph export "$mainDir/figures/FigA7_panelF_trends_total_sugar_production.pdf", as(pdf) replace
		
*POLLUTION FROM FIRES
use "$dataDir/dataset_pollution_harvest_daily_weather", clear		

collapse (mean) pm25, by(year treatment id_mills)

collapse (mean) pm25, by(year treatment)

*Panel G 
 		twoway (line pm25 year if treatment==1) (line pm25 year if treatment ==0), legend(label(1 "Regulated") label(2 "Unregulated") pos(6) cols(2)) ytitle(PM{sub:2.5} ({&mu}g/m{sup:3})) xline(2015) ylabel(0(5)25) xlab(, nogrid) xtitle("")
			graph export "$mainDir/figures/FigA7_panelG_trends_pm25_fires.pdf", as(pdf) replace

*POLLUTION FROM MILLS
use "$dataDir/dataset_pollution_mills_year_weather", replace

collapse (mean) pm25, by(year treatment id_mills)

collapse (mean) pm25, by(year treatment)
*Panel H 
 		twoway (line pm25 year if treatment==1) (line pm25 year if treatment ==0), legend(label(1 "Regulated") label(2 "Unregulated") pos(6) cols(2)) ytitle(PM{sub:2.5} ({&mu}g/m{sup:3})) xline(2015) ylabel(0(5)25) xlab(, nogrid) xtitle("")
			graph export "$mainDir/figures/FigA7_panelH_trends_pm25_mills.pdf", as(pdf) replace
		